﻿using DragonSolution.Web.Data.Entity;
using DragonSolution.Web.UI.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DragonSolution.Web.UI.Areas.AdminMrg.Controllers
{
    [CheckLogin(true)]
    public class MCompanyController : AdminBaseController
    {
        private MyDbContext db;
        public MCompanyController()
        {
            db = base.GetContext();
        }

        // GET: AdminMrg/MCompany
        public ActionResult Index()
        {
            CompanyInfo com = db.CompanyInfo.FirstOrDefault();
            if (com != null) {
                ViewData["companyBrief"] = com.CompanyBrief;
            }
            return View();
        }

        public ActionResult Edit() {
            CompanyInfo com = db.CompanyInfo.FirstOrDefault();
            if (com != null)
            {
                return View(com);
            }
            else
                return View();
        }

        [HttpPost]
        public ActionResult Edit(CompanyInfo company)
        {
            CompanyInfo c = db.CompanyInfo.FirstOrDefault();
            try
            {
                c.CompanyBrief = company.CompanyBrief;
                UpdateModel(c);
                db.SaveChanges();
                ViewData["msg"] += "更新成功";
            }
            catch (Exception)
            {
                ViewData["msg"] += "更新失败";
            }
            return View();
        }
    }
}